#pragma once

#include <functional>
#include "Sock.h"
#include "InetAddress.h"
#include "Channel.h"
#include "EventLoop.h"
#include"Buffer.h"
class Channel;
class EventLoop;
class Connection
{
public:
    using func_t = std::function<void(Connection *)>;

public:
    Connection(EventLoop *loop, Sock *clentSock);
    ~Connection();

    std::string getIp() const;
    uint16_t getPort() const;
    int getFd() const;

    void closecallback();
    void errorcallback();


    void onmessage();                     // 处理对端发送过来的消息。
    void setCloseCallBack(func_t fn);
    void setErrorCallBack(func_t fn);

private:
    Buffer inputBuffer_;
    Buffer outputBuffer_;
    EventLoop *loop_;
    Sock *clientSock_;
    Channel *clientChannel_;
    func_t closeCallBack_;
    func_t errorCallBack_;
};
